package de.stalinski.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Logging
{

    public final static int ERROR = 0;

    public final static int WARNING = 1;

    public final static int INFO = 2;

    public static void log(int type, Exception ex, String cls)
    {
        StackTraceElement[] ste = ex.getStackTrace();
        String out = "";
        Date now = new Date(System.currentTimeMillis());
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy - hh:mm:ss");
        String date = df.format(now);
        switch ( type ) {
            case ERROR:
                out += "[ERROR] "+date+" : " + ex.getClass().getName() + " <" + ex.
                        getMessage() + "> in " + cls + " @ Line ";
                for ( StackTraceElement e : ste ) {
                    if ( e.getClassName().equals(cls) ) {
                        out += e.getLineNumber();
                    }
                }
                System.out.println(out);
                break;
            case WARNING:
                out += "[WARNING] "+date+" : " + ex.getClass().getName() + " <" + ex.
                        getMessage() + "> in " + cls + " @ Line ";

                for ( StackTraceElement e : ste ) {
                    if ( e.getClassName().equals(cls) ) {
                        out += e.getLineNumber();
                    }
                }
                System.out.println(out);
                break;
            case INFO:
                out += "[INFO] "+date+" : " + ex.getClass().getName() + " <" + ex.
                        getMessage() + "> in " + cls + " @ Line ";
                for ( StackTraceElement e : ste ) {
                    if ( e.getClassName().equals(cls) ) {
                        out += e.getLineNumber();
                    }
                }
                System.out.println(out);
                break;
            default:
                break;
        }
        
    }

}
